package com.gaohe.web.controller.hotal;

import com.gaohe.common.annotation.Log;
import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.core.page.TableDataInfo;
import com.gaohe.common.enums.BusinessType;
import com.gaohe.common.utils.poi.ExcelUtil;
import com.gaohe.hotal.domain.HotFlow;
import com.gaohe.hotal.service.IHotFlowService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 财务流水Controller
 *
 * @author ruoyi
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/hotal/flow")
public class HotFlowController extends BaseController
{
    @Autowired
    private IHotFlowService hotFlowService;

    /**
     * 查询财务流水列表
     */
    @PreAuthorize("@ss.hasPermi('hotal:flow:list')")
    @GetMapping("/list")
    public TableDataInfo list(HotFlow hotFlow)
    {
        startPage();
        List<HotFlow> list = hotFlowService.selectHotFlowList(hotFlow);
        return getDataTable(list);
    }

    /**
     * 导出财务流水列表
     */
    @PreAuthorize("@ss.hasPermi('hotal:flow:export')")
    @Log(title = "财务流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotFlow hotFlow)
    {
        List<HotFlow> list = hotFlowService.selectHotFlowList(hotFlow);
        ExcelUtil<HotFlow> util = new ExcelUtil<HotFlow>(HotFlow.class);
        util.exportExcel(response, list, "财务流水数据");
    }

    /**
     * 获取财务流水详细信息
     */
    @PreAuthorize("@ss.hasPermi('hotal:flow:query')")
    @GetMapping(value = "/{flowId}")
    public AjaxResult getInfo(@PathVariable("flowId") Long flowId)
    {
        return success(hotFlowService.selectHotFlowByFlowId(flowId));
    }

    /**
     * 新增财务流水
     */
    @PreAuthorize("@ss.hasPermi('hotal:flow:add')")
    @Log(title = "财务流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotFlow hotFlow)
    {
        return toAjax(hotFlowService.insertHotFlow(hotFlow));
    }

    /**
     * 修改财务流水
     */
    @PreAuthorize("@ss.hasPermi('hotal:flow:edit')")
    @Log(title = "财务流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HotFlow hotFlow)
    {
        return toAjax(hotFlowService.updateHotFlow(hotFlow));
    }

    /**
     * 删除财务流水
     */
    @PreAuthorize("@ss.hasPermi('hotal:flow:remove')")
    @Log(title = "财务流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowIds}")
    public AjaxResult remove(@PathVariable Long[] flowIds)
    {
        return toAjax(hotFlowService.deleteHotFlowByFlowIds(flowIds));
    }
}
